package com.example.demo.controller;

import com.example.demo.IpUtils;
import com.example.demo.controller.req.BaseRequest;
import com.example.demo.controller.resp.Response;
import com.example.demo.service.UserService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/auth/")
public class ValidateController {

    @Resource
    UserService userService;

    @PostMapping(value = "verifyAuth", consumes = MediaType.APPLICATION_JSON_VALUE)
    public Response<?> check(@RequestBody BaseRequest request, HttpServletRequest _request) {
        request.validate();
        return Response.success(userService.check(IpUtils.getIpAddress(_request), request.getActiveCode()));
    }
}
